import _ from 'lodash'

/**
 * @export 对象深度取值
 * @param {*} arr a.b
 * @param {*} obj { a: { b: { c: 1 } } }
 * @return {*} { c: 1 }
 */
export function getDeepObjectProperty (arr, obj) {
  if (!arr || !arr.length) return

  const paths = arr.split('.')
  let res = obj

  let prop = paths.shift()
  while (prop) {
    res = res[prop]
    prop = paths.shift()
  }

  return res
}

/**
 * 过滤空值
 * @param {*} obj
 */
export function filterEmptyValue (obj) {
  if (!obj) return obj
  const keys = Object.keys(obj)
  const dataObj = {}
  _.forEach(keys, (k) => {
    const v = obj[k]
    if (v !== null && v !== undefined && v !== '') {
      (dataObj[k] = v)
    }
  })
  return dataObj
}
